#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''简洁板，debug'''
import logging
import logging.config
import os

logger = logging.getLogger("debug")


def init_log(log_path, log_name, log_level = "DEBUG"):
    ''''''
    log_level = log_level.upper()

    LOG_PATH_DEBUG = "%s/%s_debug.log" % (log_path,log_name)

    #日志文件大小
    LOG_FILE_MAX_BYTES = 1 * 512 * 1024 * 1024
    #备份文件个数
    LOG_FILE_BACKUP_COUNT = 365

    log_conf = {
        "version" : 1,
        "formatters" : {
            "format1" : {
                "format" : '%(asctime)-15s [%(thread)d] - [%(filename)s %(lineno)d] %(levelname)s %(message)s',
            },
        },

        "handlers" : {

            "handler1": {
                "class" : "logging.handlers.RotatingFileHandler",
                "level" : log_level,
                "formatter" : "format1",
                "maxBytes" :  LOG_FILE_MAX_BYTES,
                "backupCount" : LOG_FILE_BACKUP_COUNT,
                "filename" : LOG_PATH_DEBUG
            },

        },

        "loggers" : {

            "debug": {
                "handlers" : ["handler1"],
                "level" : log_level
            },
        },
    }
    logging.config.dictConfig(log_conf)



CUR_PATH = os.path.dirname(os.path.abspath(__file__))
log_path = os.path.join(CUR_PATH, "./log")
if not os.path.exists(log_path):
    os.makedirs(log_path)
init_log(log_path, "dongcai_Spider")